package ar.edu.uba.fi.jmit.monitorengine.backend.server.mock;

import java.util.LinkedList;
import java.util.List;

import ar.edu.uba.fi.jmit.monitorengine.backend.client.JMitFileService;
import ar.edu.uba.fi.jmit.monitorengine.backend.shared.dto.JMitFileDTO;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class JMitFileServiceMock extends RemoteServiceServlet implements JMitFileService {

	private static final long serialVersionUID = -147334874124107597L;
	
	private List<JMitFileDTO> list;
	
	public JMitFileServiceMock() {
		super();
		list = new LinkedList<JMitFileDTO>();
		JMitFileDTO dto = new JMitFileDTO();
		dto.setName("MockConifgurationFile1.jmit.xml");
		dto.setPath("");
		list.add(dto);
		dto = new JMitFileDTO();
		dto.setName("MockConifgurationFile2.jmit.xml");
		dto.setPath("");
		list.add(dto);
	}

	public List<JMitFileDTO> getLoadedConfigurationFiles() {
		return list;
	}

	@Override
	public void deleteFile(String fileName) {
		for(JMitFileDTO file:list) {
			if(file.getName().equals(fileName)) {
				list.remove(file);
				return;
			}
		}
		throw new RuntimeException("File with name " + fileName + " does not exist.");
		
	}

	@Override
	public String getFileText(String fileName) {
		return "<jmit>\n" + 
		"\t<monitorengine>\n" +
			"\t\t<connection protocol=\"http\" ip=\"10.0.0.1\" port=\"8080\" context=\"monitorEngine\"/>\n" +
		"\t</monitorengine>\n" +
		"\t<monitor name=\"testInvocationCounter3\" enviroment=\"development\" application=\"Prueba\" type=\"InvocationCounter\">\n" + 
			"\t\t<configurations>\n" +
				"\t\t\t<configuration name=\"methodConfiguration\">\n" +
					"\t\t\t\t<method name=\"getX\" return=\"java.lang.Integer\" class=\"ar.edu.uba.fi.jmit.aspecter.itegration.testUtils.PointTestInvocationCounter\" id=\"x\">\n" +
						"\t\t\t\t\t<param name=\"data\" type=\"int\"/>\n" +
					"\t\t\t\t</method>\n" +
				"\t\t\t</configuration>\n" +
			"\t\t</configurations>\n" +
		"\t</monitor>\n" +
		"\t<visualizer name=\"\">\n" +
			"\t\t<monitors name=\"\"/>\n" +
		"\t</visualizer>\n" +
		"</jmit>\n";
	}
}
